package org.eraser.security;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.multipart.support.MultipartFilter;


@Configuration
public class SecurityCoreConfig {

    /**
     * 密钥协商接口路径
     */
    public final static String KEY_AGREEMENT = "/enoch/keyAgreement";

    /**
     * 登录接口路径
     */
    public final static String LOGIN_PROCESSES_URL = "/enoch/login";

    /**
     * 白名单
     */
    public static final String[] WHITE_URL;

    static {
        WHITE_URL = new String[]{LOGIN_PROCESSES_URL, KEY_AGREEMENT};
    }

    public final static String USERNAME = "username";
    public final static String PASSWORD = "password";

    /**
     * MultipartFile 文件上传过滤器
     */
    @Bean
    public MultipartFilter multipartFilter() throws Exception {
        return new MultipartFilter();
    }

    /**
     * 密码加密 BCrypt 算法
     */
    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    /**
     * Json 处理
     */
    @Bean
    public ObjectMapper objectMapper() {
        return new ObjectMapper();
    }

}
